package com.whj.apipassenger.service.impl;

import com.whj.apipassenger.remote.ServicePriceClient;
import com.whj.apipassenger.service.ForecastPriceService;
import com.whj.internalcommon.constant.CommonStatusEnum;
import com.whj.internalcommon.dto.ResponseResult;
import com.whj.internalcommon.request.ForecastPriceDTO;
import com.whj.internalcommon.response.ForecastPriceResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: wanghaijun
 * @Date: 2023/1/5 - 01 - 05 - 16:18 
 * @Description: com.whj.apipassenger.service.impl
 */
@Service
@Slf4j
public class ForecastPriceServiceImpl implements ForecastPriceService {

    @Autowired
    private ServicePriceClient servicePriceClient;

    /**
     * 根据出发地和目的地的经纬度来计算预估价格
     *
     * @param depLongitude 出发地经度
     * @param depLatitude  出发地纬度
     * @param desLongitude 目的地经度
     * @param desLatitude  目的地经度
     * @return
     */
    @Override
    public ResponseResult forecastPrice(String depLongitude, String depLatitude, String desLongitude, String desLatitude,String cityCode,String vehicleType) {

        log.info("出发地经度:" + depLongitude);
        log.info("出发地纬度:" + depLatitude);
        log.info("目的地经度:" + desLongitude);
        log.info("目的地纬度:" + desLatitude);

        log.info("调用计价服务，计算价格");
        ForecastPriceDTO forecastPriceDTO = new ForecastPriceDTO();
        forecastPriceDTO.setDepLongitude(depLongitude);
        forecastPriceDTO.setDepLatitude(depLatitude);
        forecastPriceDTO.setDesLongitude(desLongitude);
        forecastPriceDTO.setDesLatitude(desLatitude);
        forecastPriceDTO.setCityCode(cityCode);
        forecastPriceDTO.setVehicleType(vehicleType);

        ResponseResult<ForecastPriceResponse> forecast = servicePriceClient.forecast(forecastPriceDTO);
        if(forecast.getCode()==1300){
            return ResponseResult.fail(CommonStatusEnum.CITY_CAT_CODE_ERROR.getCode(),CommonStatusEnum.CITY_CAT_CODE_ERROR.getValue());
        }
        return ResponseResult.success(forecast.getData());
    }
}
